package com.pz.cloud.framework.pzStudent.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pz.cloud.framework.base.dao.CommonDao;
import com.pz.cloud.framework.base.model.Pageable;
import com.pz.cloud.framework.business.pzStudent.entity.PzClazz;
import com.pz.cloud.framework.business.pzStudent.entity.PzMajor;
import com.pz.cloud.framework.business.pzStudent.entity.PzOrg;
import com.pz.cloud.framework.business.pzStudent.entity.PzStudent;
import com.pz.cloud.framework.business.pzStudent.service.IPzStudentService;
import com.pz.cloud.framework.model.AbstractSqlBuilder;
import com.pz.cloud.framework.model.SqlBuilder;
import com.pz.cloud.framework.pzStudent.mapper.PzStudentMapper;
import org.jeecg.common.util.dynamic.db.SqlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@DS("pz")
@Service
@Transactional
public class PzStudentServiceImpl extends ServiceImpl<PzStudentMapper, PzStudent> implements IPzStudentService {

    @Autowired
    private CommonDao commonDao;

    @Override
    public List<PzStudent> findPage(PzStudent entity, Pageable pageable) {
        AbstractSqlBuilder sqlBuilder = SqlBuilder.init("select s.XH,s.XM,s.XBM,s.SFZJH,s.ZZMMM,s.RXNY,s.SZNJ,s.YXSH,s.ZYM,s.SZBH,o.DWMC,m.ZYMC,c.BJMC from ").appendTable(PzStudent.class).append(" s ")
                .append(" left join ").appendTable(PzOrg.class).append(" o on s.YXSH = o.DWH ")
                .append(" left join ").appendTable(PzMajor.class).append(" m on s.ZYM = m.ZYH ")
                .append(" left join ").appendTable(PzClazz.class).append(" c on s.SZBH = c.BH ");
        return commonDao.findList(SqlBuilder.init(SqlUtils.createPageSqlByDBType("oracle", sqlBuilder.getSql(), pageable.getPageNo(), pageable.getPageSize())).returnType(PzStudent.class));
    }
}
